import socket
import sys

try:
    bind_addr, bind_port = sys.argv[1:]
except:
    print("usage: %s BIND_ADDR BIND_PORT" % sys.argv[0])
    sys.exit(-1)

ss = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ss.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
ss.bind((bind_addr, int(bind_port)))
ss.listen(100)
print("* TCP server is ready ...")
conn, addr = ss.accept()
while 1:
    try:
        meg = raw_input('[in]: ')
    except KeyboardInterrupt:
        break
    else:
        conn.send((meg + "\n").encode("utf-8"))

ss.close()
